1466B - Last minute enhancements - CodeForces Solution


dp greedy *800

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    n = int(input())
    arr = list(map(int, input().split()))
    hm = {}
    c = 0
    for i in arr:
        if i not in hm:
            hm[i] = 1
            c += 1
        else:
            if i + 1 not in hm:
                hm[i + 1] = 1
                c += 1
    print(c)

C++ Code:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define repi(i, a, b) for(int i=a; i<b; i++)
#define rrepi(i, a, b) for(int i=a; i>=b; i--)
typedef vector<ll> vl;
typedef pair<ll,ll> pl;
#define repl(i, a, b) for(ll i=a; i<b; i++)
#define rrepl(i, a, b) for(ll i=a; i>=b; i--)
#define srt(a) sort(a.begin(), a.end());
#define rsrt(a) sort(a.rbegin(), a.rend());
#define rev(a) reverse(a.begin(), a.end());
#define mod(n) (((ll)n%1000000007+1000000007)%1000000007)
const int N=1e5+10;

void solve(){
    int n;
    cin>>n;
    vi x(n);
    map<int,int> mp;
    repi(i,0,n){
        cin>>x[i];
        mp[x[i]]++;
    }
    repi(i,0,n){
        if(mp[x[i]]>1){
            mp[x[i]]--;
            x[i]+=1;
            mp[x[i]]++;
        }
    }
    cout<<mp.size()<<"\n";
}

int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
ll t; cin>>t; while(t--)
solve();
return 0;
}


Comments

Submit
0 Comments
More Questions

1661B - Getting Zero
1661A - Array Balancing
1649B - Game of Ball Passing
572A - Arrays
1455A - Strange Functions
1566B - MIN-MEX Cut
678C - Joty and Chocolate
1352E - Special Elements
1520E - Arranging The Sheep
1157E - Minimum Array
1661D - Progressions Covering
262A - Roma and Lucky Numbers
1634B - Fortune Telling
1358A - Park Lighting
253C - Text Editor
365B - The Fibonacci Segment
75A - Life Without Zeros
1519A - Red and Blue Beans
466A - Cheap Travel
659E - New Reform
1385B - Restore the Permutation by Merger
706A - Beru-taxi
686A - Free Ice Cream
1358D - The Best Vacation
1620B - Triangles on a Rectangle
999C - Alphabetic Removals
1634C - OKEA
1368C - Even Picture
1505F - Math
1473A - Replacing Elements